package com.xuzm.netty.dto;

import io.netty.channel.ChannelHandlerContext;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Objects;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class ServerHandlerConsumer {
    private Consumer<ChannelHandlerContext> addConsumer;
    private BiConsumer<ChannelHandlerContext, Object> readConsumer;
    private BiConsumer<ChannelHandlerContext, Throwable> exceptionConsumer;
    private Consumer<ChannelHandlerContext> removeConsumer;

    public Consumer<ChannelHandlerContext> getAddConsumer() {
        return Objects.isNull(addConsumer)? ctx->{}:addConsumer;
    }

    public BiConsumer<ChannelHandlerContext, Object> getReadConsumer() {
        return Objects.isNull(readConsumer)? (ctx, msg)->{}:readConsumer;
    }

    public BiConsumer<ChannelHandlerContext, Throwable> getExceptionConsumer() {
        return Objects.isNull(exceptionConsumer)? (ctx, exception)->{}:exceptionConsumer;
    }

    public Consumer<ChannelHandlerContext> getRemoveConsumer() {
        return Objects.isNull(removeConsumer)? ctx->{}:removeConsumer;
    }
}
